# -*- coding: utf-8 -*-
import pendulum
from datetime import timedelta
from airflow.operators.python import PythonOperator
from airflow.exceptions import AirflowSkipException
from .dwd_track_broken_detail_success import main
from jms_point_hi.dwd.dwd_track_broken_detail import jms_dwd__dwd_track_broken_detail

cst = pendulum.timezone('Asia/Shanghai')

class TrackBrokenSensor(PythonOperator):

    def pre_execute(self, context):
        day = cst.convert(context['ti'].execution_date) + timedelta(hours=1)

        schedule_date = ['05']

        if day.strftime('%H') not in schedule_date:
            print(f'{day.strftime("%H")} not in {schedule_date}, should skip')
            super().pre_execute(context)
            raise AirflowSkipException()
        else:
            print(f'{day.strftime("%H")} in {schedule_date}, run now')
            super().pre_execute(context)


jms_dwd__dwd_track_broken_detail_success = TrackBrokenSensor(
    task_id='jms_dwd_dwd_track_broken_detail_success',
    email=['jarl.huang@jtexpress.com','yl_bigdata@yl-scm.com'],
    pool='unlimited_pool',
    python_callable=main,
    op_args=['{{ execution_date | date_add(-1) | cst_ds }}', '{{ var.json.mysq_sync_status2kafka }}'],
)

jms_dwd__dwd_track_broken_detail_success << [jms_dwd__dwd_track_broken_detail]